﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Service.aspx.cs" Inherits="Enterprise.Admin.Service" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/Widget/fancyBox/jquery.fancybox.css" rel="stylesheet" />
    <link href="../Content/Widget/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
    <link href="../Content/Widget/uploadify/uploadify.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_article">
        <form id="search_article_form" action="Handle/GetArticleListJson.aspx" method="post">
            <p>
                <label>分类：</label><input id="search_article_categroy_id" class="input_select" name="CoArticleCategoryId" />
            </p>
            <p>
                <label>标题：</label><input type="text" class="input_text input_title" name="CoTitle" />
            </p>
            <p>
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox input_select">
                    <option value="">全部</option>
                    <option value="zh_cn">中文</option>
                    <option value="en_us">英语</option>
                </select>
            </p>
        </form>
    </div>
    <div id="add_article">
        <form id="add_article_form" action="Handle/AddArticle.aspx" method="post">
            <div id="add_article_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>分类：</label><input id="add_article_categroy_id" class="input_select" name="CoarticleCategoryId" />
                        <input id="add_cover_image_id" name="CoCoverImageId" type="hidden" value="" />
                    </p>
                    <p>
                        <label>标题：</label><input type="text" name="CoTitle" class="input_text input_title" />
                    </p>
                    <p>
                        <label style="height: 130px; line-height: 130px;">概要：</label><textarea rows="5" cols="30" name="CoSummary"></textarea>
                    </p>

                    <p>
                        <label>发布日期：</label><input type="text" name="CoDate" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>" class="easyui-datetimebox input_date" />
                    </p>
                    <p>
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox input_select" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" class="input_checkbox" value="true" />

                    </p>
                </div>
                <div title="内容" style="height: 100%">
                    <textarea cols="" rows="" name="CoContent" id="add_article_content" class="input_textarea"></textarea>
                </div>
                <div title="图片管理" style="display: block;">
                    <div class="image_um">
                        <input id="add_file_upload" name="file_upload" type="file" multiple="true" />
                    </div>
                    <div>
                        <ul id="add_article_image_ul" class="image_list_tt">
                        </ul>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="edit_article">
        <form id="edit_article_form" action="Handle/EditArticle.aspx" method="post">
            <div id="edit_article_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>分类：</label><input id="edit_article_categroy_id" name="CoArticleCategoryId" />
                        <input id="edit_article_id" name="CoArticleId" type="hidden" value="" />
                        <input id="edit_cover_image_id" name="CoCoverImageId" type="hidden" value="" />
                    </p>

                    <p>
                        <label>标题：</label><input type="text" name="CoTitle" value="" class="input_text input_title" />
                    </p>
                    <p>
                        <label style="height: 130px; line-height: 130px;">概要：</label><textarea rows="5" cols="30" name="CoSummary"></textarea>
                    </p>
                    <p>
                        <label>发布日期：</label><input type="text" id="edit_date" name="CoDate" value="" class="easyui-datetimebox input_date" />
                    </p>

                    <p class="multi-language ">
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="true" />

                    </p>
                </div>
                <div title="内容" style="height: 100%">
                    <textarea rows="" cols="" name="CoContent" id="edit_article_content" class="input_textarea"></textarea>
                </div>
                <div title="图片管理" style="display: block;">
                    <div class="image_um">
                        <input id="edit_file_upload" name="file_upload" type="file" multiple="true" />
                    </div>
                    <div>
                        <ul id="edit_article_image_ul" class="image_list_tt">
                        </ul>
                    </div>
                </div>
            </div>
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '技术服务列表',
                url: 'Handle/GetArticleListJson.aspx',
                idField: 'id',
                singleSelect: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                columns: [[
                         { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                         { title: '标题', field: 'CoTitle', width: 280, align: 'center', sortable: true },
                         { title: '发布日期', field: 'CoDate', width: 180, align: 'center', sortable: true },
                         { title: '分类', field: 'CoCategoryName', width: 100, align: 'center' },
                         {
                             title: '语言', field: 'CoLanguage', width: 100, align: 'center',
                             formatter: function (value) {
                                 var text;
                                 $.each(languageData, function () {
                                     if (this.id == value) {
                                         text = this.text;
                                         return false;
                                     }
                                     return true;
                                 });
                                 return text;
                             }
                         },
                    {
                        field: 'CoIsRecommend', title: '推荐', width: 60, align: 'center',
                        formatter: function (value) {
                            return value ? '是' : '否';
                        }
                    },

                       {
                           title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                               return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                           }
                       },
                        {
                            title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';
                            }
                        }
                ]]
            });
            $('#add_article').dialog({
                title: '添加',
                width: 750,
                height: 500,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addArticleContent.sync();
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_article').dialog('close');
                    }
                }]
            });
            $('#edit_article').dialog({
                title: '修改',
                width: 750,
                height: 500,
                closable: true,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editArticleDescription.sync();
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_article').dialog('close');
                    }
                }]
            });
            $('#search_article').dialog({
                title: '检索',
                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_article_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_article').dialog('close');
                    }
                }]
            });
            $('#edit_article_form').form({
                onLoadSuccess: function (data) {
                    editArticleDescription.html(data.CoContent);
                    $("#edit_article_image_ul").html('');
                    $.each(data.ArticleImage, function () {
                        $("#edit_article_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/article/' + this.thumFileName + '"/>   <input type="hidden" name="CoArticleImageId" value="' + this.id + '"/></div></div><div class="img_l_r"><p><input class="edit_set_cover" name="edit_set_cover" ' + (this.id == data.CoCoverImageId ? 'checked="checked"' : '') + ' valuedata="' + this.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_article_image" value="' + this.id + '">删除图片</a></p></div></li>');
                    });
                    $('#edit_date').datetimebox('setValue', data.CoDate);
                    $('#edit_article').dialog("open");
                }
            });
            $('#add_article_tabs').tabs();
            $('#edit_article_tabs').tabs();
            var addArticleContent = window.KindEditor.create('#add_article_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true
            });
            var editArticleDescription = window.KindEditor.create('#edit_article_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false
            });
            $.ajax({
                type: "POST",
                url: "Handle/GetArticleCategoryTreeDataJson.aspx",
                success: function (data) {
                    var searchData = data.concat();
                    $('#add_article_categroy_id').combotree({
                        data: data,
                    }); $('#edit_article_categroy_id').combotree({
                        data: data,
                    });
                    searchData.unshift({ id: '', text: '全部' });
                    $('#search_article_categroy_id').combotree({
                        data: searchData
                    });
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
            $("#add_file_upload").uploadify({
                'overrideEvents': ['onUploadSuccess'],
                'buttonText': '浏览...',
                'width': 100,
                'swf': '../Content/Widget/uploadify/uploadify.swf',
                'uploader': 'Handle/AddArticleImage.aspx',
                'fileTypeExts': '*.gif; *.jpg; *.png',
                'formData': {
                    'CoArticleId': '',
                    'ASPSESSID': '<%=Aspsessid%>', 'AUTHID': '<%=Auth%>'
                },
                'onUploadSuccess': function (file, data) {
                    var msg = $.parseJSON(data);
                    if (msg.state) {
                        $('#' + file.id).find('.data').html(' - 完成');
                        $("#add_article_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/Article/' + msg.thumFileName + '"/>   <input type="hidden" name="CoArticleImageId" value="' + msg.id + '"/></div></div><div class="img_l_r"><p><input class="add_set_cover" name="add_set_cover" valuedata="' + msg.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_article_image" value="' + msg.id + '">删除图片</a></p></div></li>');
                    } else {
                        $('#' + file.id).find('.data').html(' - 失败');
                        $.messager.show({
                            title: '提示',
                            msg: file.name + "上传失败\n错误:" + msg.message,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                }
            });

            $("#edit_file_upload").uploadify({
                'overrideEvents': ['onUploadSuccess'],
                'buttonText': '浏览...',
                'width': 100,
                'swf': '../Content/Widget/uploadify/uploadify.swf',
                'uploader': 'Handle/AddArticleImage.aspx',
                'fileTypeExts': '*.gif; *.jpg; *.png',
                'formData': {
                    'CoArticleId': '',
                    'ASPSESSID': '<%=Aspsessid%>', 'AUTHID': '<%=Auth%>'
                },
                'onUploadStart': function () {
                    $('#edit_file_upload').uploadify('settings', 'formData', { 'CoArticleId': $('#edit_article_id').val() });
                },
                'onUploadSuccess': function (file, data) {
                    var msg = $.parseJSON(data);
                    if (msg.state) {
                        $('#' + file.id).find('.data').html(' - 完成');
                        $("#edit_article_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/Article/' + msg.thumFileName + '"/>   <input type="hidden" name="CoArticleImageId" value="' + msg.id + '"/></div></div><div class="img_l_r"><p><input class="edit_set_cover" name="edit_set_cover" valuedata="' + msg.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_article_image" value="' + msg.id + '">删除图片</a></p></div></li>');

                    } else {
                        $('#' + file.id).find('.data').html(' - 失败');
                        $.messager.show({
                            title: '提示',
                            msg: file.name + "上传失败\n错误:" + msg.message,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                }
            });
            $('.delete_article_image').live('click', function () {
                delImage(this);
            });
            $('.add_set_cover').live('click', function () {
                $('#add_cover_image_id').val($(this).attr('valuedata'));
            });
            $('.edit_set_cover').live('click', function () {
                $('#edit_cover_image_id').val($(this).attr('valuedata'));
            });
        });
        //获取详细
        function edit(id) {
            if (id == '' || id == undefined) {
                var selectData = $('#table_list').datagrid('getSelected');
                if (selectData == null) {
                    $.messager.show({
                        title: '提示',
                        msg: '请选择要修改记录！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                    return;
                } else {
                    id = selectData.id;
                }
            }
            $('#edit_article_form').form('load', 'Handle/GetarticleDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeleteArticle.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });
        }
        function add() {
            var selectData = $('#table_list').datagrid('getSelected');
            if (selectData == null) {
                $.messager.show({
                    title: '提示',
                    msg: '请选择要修改记录！',
                    timeout: 5000,
                    showType: 'fade'
                });
            } else {
                edit(selectData.id);
            }
            $('#add_article').dialog("open");
        }

        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/AddArticle.aspx",
                data: $('#add_article_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_article_form')[0].reset();
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/EditArticle.aspx",
                data: $('#edit_article_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        function delImage(th) {
            $.ajax({
                type: "POST",
                url: "Handle/DeleteArticleImage.aspx",
                data: { id: $(th).attr('value') },
                context: $(th),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $(th).parentsUntil('li').parent().remove();
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        search = function search() {
            $('#search_article').dialog("open");
        };
    </script>
    <script src="../Content/Widget/fancyBox/jquery.fancybox.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.mousewheel.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.easing.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/kindeditor-min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/uploadify/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/jquery.json.min.js" type="text/javascript" charset="utf-8"></script>
</asp:Content>
